
import treenode.TreeNode;

import java.util.*;


/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * User:Mr.Du
 * Date:2022/3/22
 * Time:21:46
 */
public class 统计字符1个数 {

    public static void main(String[] args) {
        boolean bcdefg = isDu("bcdaefg", 0);
        System.out.println(bcdefg);
        String s = "abcabcbb";
        List<Character> list = new ArrayList<>();
        int size = s.length();
        int res = 0,slow = 0,fast = 0;
        while(fast < size){
            if(!list.contains(s.charAt(fast))){
                list.add(s.charAt(fast));
                fast++;
            }else{
                list.clear();
                slow++;
                fast = slow;
            }
            res = Math.max(res,fast - slow);
        }
        System.out.println(res);
    }
    
    public void test(){
        List<TreeNode> queue = new LinkedList<>();
        
        
        String s = "happy";
        int[] arr = new int[256];
        int size = s.length();
        int res = 0;
        int slow = 0;
        int fast = 0;
        while(fast < size){
            int index = s.charAt(fast) - 0;
            arr[index] += 1;
            while(arr[index] > 1){
                int index1 = s.charAt(slow) - 0;
                arr[index1] -= 1;
                slow++;
            }
            fast++;
            res = Math.max(res,fast - slow);
        }
        
    
    }
    
    public static boolean isDu(String s,int i){
        if(i == s.length() - 1) return false;
        if(s.charAt(i) == 'a') {
            return false;
        }
        isDu(s,i+1);
        return true;
    }
    
    
    public int lengthOfLongestSubstring(String s){
        int size = s.length(), res = 0, start = 0, end = 0;
        Map<Character, Integer> mp = new HashMap<>();
        while(end < size){
            char tmp = s.charAt(end);
            if (mp.containsKey(tmp)) {
                start = Math.max(mp.get(tmp), start);
            }
            res = Math.max(res, end - start + 1);
            mp.put(s.charAt(end), end + 1);
            end++;
        }
        return res;
    }

}
